  <!-- 验证插件 -->
<script src="/static/plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="/static/plugins/jquery-validation/localization/messages_zh.min.js"></script>
<!-- 针对当前主题进行简单封装，精简代码 -->
<script src="/static/sdtheme/scripts/sdvalidate.js"></script>
<script src="/static/product/scripts/common.js"></script>
<script>
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    $(function () {
        //验证
        validateInfo();
        //studentSelectInit();
        //lengthSelectInit ('{{.length}}');
    });
    //表单验证及AJAX提交
    function validateInfo() {
        var $thisForm = $('#thisForm');
        $thisForm.sdvalidate({
            rules: {
                Name: {
                    maxlength: 32,
                    required: true
                }
            },
            messages: {},
            submitHandler: function (form) {
                var url ='{{ urlfor "teacher/TeacherSubjectController.Edit"}}';
                var data = $thisForm.serialize();
                $.sdpost(url,data,function(re){
                    if(re.code === 0){
                        parent.layer.msg(re.msg);
                        parent.refresh(re.obj);
                        parent.layer.close(index);
                    }else{
                        parent.layer.alert(re.msg,{icon:2,title:'失败'})
                    }
                });
                return false;
            }
        });
    }

    function FormSubmit() {
        $("#thisForm").submit();
    }

    function studentSelectInit(ths, selecteds) {
        console.log(selecteds);
        var url = '{{urlfor "student/StudentController.DataList"}}';
        var $select = $(ths);
        $select.html('');
        $.sdpost(url,{"Status":"1","Type":100},function (re) {
            if(re.code === 0) {
                var html=['<option value="">   </option>'];
                $(re.obj).each(function(i,e){
                    html.push('<option value="' + e.id + '">' + e.name + '</option>')
                });
                $select.html(html.join(''));
                $select.selectpicker({liveSearch:true});
                $select.selectpicker('val',selecteds);
            }else {
                layer.alert("获取数据失败",{icon:2,title:'失败'})
            }
        })
    }
    function lengthSelectInit(thi, selecteds) {
        selecteds = selecteds.toString();
        var $select = $(thi);
        $select.html('');
        var obj = lengthMap;
        var html=['<option value=""> </option>'];
        $(obj).each(function(i,e){
            html.push('<option value="' + e + '">' + e + '</option>')
        });
        $select.html(html.join(''));
        $select.selectpicker({liveSearch:true});
        $select.selectpicker('val',selecteds.split(','));
    }
    function edit(id) {
        console.log(id);
        $thisForm = $('#'+id);
        var url ='{{ urlfor "class/ScheduleController.Edit"}}';
        var data = $thisForm.serialize();
        $.sdpost(url,data,function(re){
            if(re.code === 0){
                parent.layer.msg(re.msg);
                // parent.refresh(re.obj);
                // parent.layer.close(index);
            }else{
                parent.layer.alert(re.msg,{icon:2,title:'失败'})
            }
        });
        return false;
    }
    function clearClass(id) {
        var url ='{{ urlfor "class/ScheduleController.Clear"}}';
        layer.confirm('您是否确认清空该排课记录？', {
            btn: ['是', '否'], icon: 3, title: '请确认'
        }, function () {
            $.sdpost(url, {"id":id}, function (re) {
                if (re.code === 0) {
                    layer.msg(re.msg, {icon: 1, title: '成功'});
                    sleep(2000);
                    window.location.reload();
                } else {
                    layer.alert(re.msg, {icon: 2, title: "失败"});
                }
            });
        });
    }
    function sleep(n) { //n表示的毫秒数
        var start = new Date().getTime();
        while (true) if (new Date().getTime() - start > n) break;
    }
</script>